home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / libexec / hotplugd / amd-localdev.pl next >
Encoding:
Perl Script  |  2001-02-28  |  1.1 KB  |  61 lines

  1. #!/usr/bin/perl
  2.  
  3. # sda          dev:=/dev/sda4;addopts:=utimeout=5
  4.  
  5. $option = shift @ARGV;
  6. $device = shift @ARGV;
  7. $mntline= shift @ARGV;
  8.  
  9. if (!$option || !$device) {
  10.     print STDERR "$0\t--insert <device> [<mntline>]\n";
  11.     print STDERR "\t--remove <device>\n";
  12.     exit 0;
  13. }
  14.  
  15. if (!$mntline || ($mntline eq "")) {
  16.     $mntline = "dev:=/dev/$device;addopts:=utimeout=5";
  17. }
  18.  
  19. %devs = ();
  20. $done = 0;
  21.  
  22. open(LOCALDEV,"/etc/am.d/localdev")||die "cannot open localdev:$!\n";
  23. @localdev = <LOCALDEV>;
  24. chomp(@localdev);
  25. foreach (@localdev) {
  26.     chomp;
  27.     next if (/^#/);
  28.     next if (/^\s*$/);
  29.  
  30.     next unless (/^([a-zA-Z0-9*]*)\s*(.*)$/);
  31.     if ($1 eq $device) {
  32.         if ($option eq '--remove') {
  33.             $_ = "";
  34.         } else {
  35.             if ($option eq '--insert') {
  36.                 $_ = "$device\t\t$mntline";
  37.             }
  38.         }
  39.         $done = 1;
  40.         last;
  41.     }
  42. }
  43. close(LOCALDEV);
  44.  
  45. if (!$done) {
  46.     if ($option eq '--insert') {
  47.         push @localdev,"$device\t\t$mntline";
  48.     }
  49.     if ($option eq '--remove') {
  50.         exit 0;    # no need to rewrite localdev
  51.     }
  52. }
  53.  
  54. open(LOCALDEV,">/etc/am.d/localdev")||die "could not open localdev for writing:$!\n";
  55. print LOCALDEV join("\n",@localdev) . "\n";
  56.  
  57. close(LOCALDEV);
  58.  
  59. mkdir("/mnt/$device",755);
  60. system("/usr/bin/amq -f");
  61.